namespace CISLib
{
    using System;
    using System.Data;

    public class ManageLog
    {
        public static DataSet GetLog()
        {
            string strSQL = "Select * from Tb_SysLog ";
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.DBSetSelect(strSQL);
            return MyDB.DBReturnDataSet();
        }

        public static DataSet GetLog(DateTime startTime, DateTime endTime)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.AddParameters(startTime, "StartTime", SqlDbType.DateTime);
            MyDB.AddParameters(endTime, "EndTime", SqlDbType.DateTime);
            string strSQL = "Select top 3000 Tb_SysLog.* from Tb_SysLog where Tb_SysLog.LogTime >= @StartTime and Tb_SysLog.LogTime <= @EndTime order by Tb_SysLog.LogTime desc";
            MyDB.DBOpen();
            MyDB.DBSetSelect(strSQL);
            return MyDB.DBReturnDataSet();
        }

        public static void InsertLog(Guid userId, string userName, DateTime logTime, string operateType, string userIp, string customerName)
        {
            Guid id = Guid.NewGuid();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(userName, "UserName", SqlDbType.VarChar);
            MyDB.AddParameters(logTime, "LogTime", SqlDbType.DateTime);
            MyDB.AddParameters(operateType, "OperateType", SqlDbType.VarChar);
            MyDB.AddParameters(userIp, "UserIp", SqlDbType.VarChar);
            MyDB.AddParameters(customerName, "CustomerName", SqlDbType.VarChar);
            string strSQL = "Insert into Tb_SysLog (UserId,UserName,LogTime,OperateType,UserIp,CustomerName) values (@UserId,@UserName,@LogTime,@OperateType,@UserIp,@CustomerName)";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static void InsertLog(Guid userId, string userName, DateTime logTime, string operateType, string userIp, string customerName, Guid customerId)
        {
            Guid id = Guid.NewGuid();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(userName, "UserName", SqlDbType.VarChar);
            MyDB.AddParameters(logTime, "LogTime", SqlDbType.DateTime);
            MyDB.AddParameters(operateType, "OperateType", SqlDbType.VarChar);
            MyDB.AddParameters(userIp, "UserIp", SqlDbType.VarChar);
            MyDB.AddParameters(customerName, "CustomerName", SqlDbType.VarChar);
            MyDB.AddParameters(customerId, "CustomerId", SqlDbType.UniqueIdentifier);
            string strSQL = "Insert into Tb_SysLog (UserId,UserName,LogTime,OperateType,UserIp,CustomerName,CustomerId) values (@UserId,@UserName,@LogTime,@OperateType,@UserIp,@CustomerName,@CustomerId)";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }
    }
}

